﻿Public Class perRoyalties
    Inherits AcessoBd

    Public Function selecionarRoyalties(ByVal sMarca As String, ByVal iCodMarca As Integer) As Double
        Dim sSql As String
        Dim dtConsulta As DataTable
        Dim dRetorno As Double = 0

        sSql = "SELECT percentual" &
               "  FROM Royalties" &
               " WHERE ISNULL(marca,0) > 0"

        If sMarca <> "" Then
            sSql &= " AND descMarca = @descMarca"
        End If

        If iCodMarca > 0 Then
            sSql &= " AND Marca = @codMarca"
        End If

        Try
            With MyBase.SQLCmd.Parameters
                .Clear()
                .AddWithValue("@descMarca", sMarca)
                .AddWithValue("@codMarca", iCodMarca)
            End With

            dtConsulta = MyBase.executarConsulta(sSql)

            If Not dtConsulta Is Nothing AndAlso dtConsulta.Rows.Count > 0 Then
                dRetorno = Conversao.nuloParaZero(dtConsulta.Rows(0).Item("percentual"))
            End If

        Catch ex As Exception

            Throw New Exception("Ocorreu um erro ao selecionar os royalties da marca." & Environment.NewLine & ex.Message)

        End Try

        Return dRetorno

    End Function
End Class
